/**
 * 
 */
package com.google.code.pos.service.impl;

import com.google.code.pos.dao.ItemDao;
import com.google.code.pos.domain.Item;
import com.google.code.pos.service.JdbcService;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.DataSource;

/**
 * @author jimmy
 *
 */
public class JdbcServiceImpl implements JdbcService {

    private Connection connection;
    private ItemDao itemDao;

    @Override
    public void setConnection(DataSource dbSource) {
        try {
            connection = dbSource.getConnection();
            itemDao = new ItemDao();
            itemDao.setConnection(connection);
        } catch (SQLException ex) {
            System.out.println("exception : " + ex.getMessage());
            Logger.getLogger(JdbcServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void saveOrUpdateItem(Item item) {
        itemDao.saveOrUpdate(item);
    }

    @Override
    public void deleteItem(Item item) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Item> findAllItem() {
        return itemDao.findAllItem();
    }

    @Override
    public List<Item> findItemsByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
	
}
